/**
 * 
 */
package poc.android.model;

import java.util.Map;

import org.json.JSONObject;

/**
 * Abstract class for POJO/model supporting JSON conversion. There are mainly 
 * 2 methods to implement:
 * <ul>
 * 	<li>toJSon -- convert "this" into a valid JSONObject</li>
 * 	<li>toObjectFromJSonString -- convert a "String" into a valid "this"</li>
 * 	<li>toObjectFromJSonObject -- convert a "JSONObject" into a valid "this"</li>
 * </ul>
 * @author Jason
 *
 */
public abstract class AbstractJSonModel {
	/**
	 * the field for identification on which type of Object the JSON represents
	 */
	public static final String ID_FIELD="className";
	
	/**
	 * method to transform this object into a JSONObject; implementation 
	 * specific and the correctness might varies as well...
	 * @param pConfig
	 * @return
	 */
	public abstract JSONObject toJSon(Map<String, Object> pConfig);
	
	/**
	 * method to transform a String (assume in valid JSON format) to "this" <p/>
	 * Default implementation is throw an IllegalStateException
	 * @param pJSonString
	 * @return
	 * @see #toObjectFromJSonObject(JSONObject)
	 */
	public static Object toObjectFromJSonString(String pJSonString) {
		throw new IllegalStateException("[AbstractJSonModel][toObjectFromJSonString] not yet implemented~");
	}
	/**
	 * method to transform a JSONObject to "this"<p/>
	 * Default implementation is throw an IllegalStateException
	 * @param pJSonObject
	 * @return
	 * @see #toObjectFromJSonString(String)
	 */
	public static Object toObjectFromJSonObject(JSONObject pJSonObject) {
		throw new IllegalStateException("[AbstractJSonModel][toObjectFromJSonObject] not yet implemented~");
	}
}
